package com.eastfair.builder.service.impl;

import com.eastfair.builder.service.BuilderExhibitionServiceProviderService;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.venuebooking.api.ExhibitionServiceProviderFeign;
import com.eastfair.venueservice.dto.ExhibitionServiceProviderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 综合服务展会服务商关系 service.
 *
 * @author dqq
 * @date 2022 /12/14
 */
@Service
@Slf4j
public class BuilderExhibitionServiceProviderServiceImpl implements BuilderExhibitionServiceProviderService {

    @Resource
    private ExhibitionServiceProviderFeign exhibitionServiceProviderFeign;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveExhibitionServiceProvider(ExhibitionServiceProviderDTO param) {
        log.info("saveExhibitionServiceProvider - 保存展会服务商关系, param={}", param);
        R<Boolean> result = exhibitionServiceProviderFeign.saveExhibitionServiceProvider(param);
        log.info("saveExhibitionServiceProvider - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByServiceProviderId(ExhibitionServiceProviderDTO param) {
        log.info("deleteByServiceProviderId - 删除展会下的服务商关系, param={}", param);
        R<Boolean> result = exhibitionServiceProviderFeign.deleteByServiceProviderId(param);
        log.info("deleteByServiceProviderId - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }
}
